import xml.dom.minidom

if __name__ == "__main__":
    prefix = '..\\Libraries\\nxp_libraries\\'
    source_list = []
    DOMTree = xml.dom.minidom.parse('../../MDK-ARM/RT106X.uvprojx')
    for group in DOMTree.documentElement.getElementsByTagName('Group'):
        group_name = group.getElementsByTagName("GroupName")[0].childNodes[0].data
        print("GroupName: %s" % group_name)
        for file in group.getElementsByTagName('File'):
            if len(file.getElementsByTagName("FilePath")) > 0:
                FilePath = file.getElementsByTagName("FilePath")[0].childNodes[0].data
                if FilePath.startswith(prefix):
                    source = FilePath[len(prefix):].replace('\\', '/')
                    source_list.append(source)
                    # print("path: %s" % source)
    print(source_list)
    code = 'add_library(nxp_libraries STATIC '
    for source in source_list:
        code += '"' + source + '" '
    code += ' )'
    print(code)
